from django.http import HttpResponse
from django.shortcuts import render
from django.views import View
from kombu.utils import json

from users.forms import UploadImageForm, UserInfoForm
from utils.mixin_utils import LoginRequiredMixin


class UploadImageView(LoginRequiredMixin, View):
    # 用户信息
    def get(self, request):
        return render(request, 'usercenter-info.html')

    # 用户图像修改
    def post(self, request):
        user_info_form = UserInfoForm(request.POST, instance=request.user)
        if user_info_form.is_valid():
            user_info_form.save()
            return HttpResponse('{"status":"success"}', content_type='application/json')
        else:
            return HttpResponse(json.dumps(user_info_form.errors), content_type='application/json')
